<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        border: solid;
        display: flex;
      }
      #box input {
        flex-grow: 1;
      }
    </style>
  </head>
  <body>
    <div id="box">hello</div>
    <script>
      const box = document.getElementById("box");
      box.onclick = function () {
        // 1 获取box内容
        const boxContent = this.innerText;
        // 2 创建输入框
        // const input = `<input data-editor onclick="event.stopPropagation()" type="text" value="${boxContent}">`;
        const input = document.createElement("input");
        input.value = boxContent;
        input.onclick = (e) => e.stopPropagation();
        // 3 将输入框覆盖到box
        box.innerHTML = "";
        box.append(input);
        input.focus();
      };

      document.addEventListener("focusout", () => {
        console.log("focusout");
      });
    </script>
  </body>
</html>
